package au.edu.swin.videoshop.persistence;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@NamedQueries({
	@NamedQuery (
			name="findAllTitleCopies", 
			query="SELECT t FROM TitleCopyEntity t WHERE t.deleted = FALSE"
	),
	@NamedQuery (
			name="findTitleCopiesByStoreId", 
			query="SELECT t FROM TitleCopyEntity t WHERE t.deleted = FALSE AND t.store.storeId=:storeId"
	)
})
@Table(name="TITLE_COPY")
public class TitleCopyEntity implements Serializable{
	private String mTitleCopyId;
	private TitleMediumEntity mTitleMedium;
	private StoreEntity mStore;
	
	//Attribute to mark the entity as deleted
	private boolean mDeleted;
	private String mDeleteInfo;
	
	public TitleCopyEntity() {
		mDeleted = false;
	}
	
	/**
	 * @return the titleCopyId
	 */
	@Id
	@Column(name="TITLE_COPY_ID", length=20)
	public String getTitleCopyId() {
		return mTitleCopyId;
	}

	/**
	 * @param titleCopyId the titleCopyId to set
	 */
	public void setTitleCopyId(String titleCopyId) {
		mTitleCopyId = titleCopyId;
	}
	
	/**
	 * @return the titleMedium
	 */
	@ManyToOne(optional=false, fetch=FetchType.EAGER)
	@JoinColumn(name="TITLE_MEDIUM_ID")
	public TitleMediumEntity getMedium() {
		return mTitleMedium;
	}
	/**
	 * @param titleMedium the titleMedium to set
	 */
	public void setMedium(TitleMediumEntity titleMedium) {
		mTitleMedium = titleMedium;
	}


	/**
	 * @return the store
	 */
	@ManyToOne(optional=false, fetch=FetchType.EAGER)
	@JoinColumn(name="STORE_ID")
	public StoreEntity getStore() {
		return mStore;
	}

	/**
	 * @param store the store to set
	 */
	public void setStore(StoreEntity store) {
		mStore = store;
	}
	
	/**
	 * @return the deleted
	 */
	@Column(name="IS_DELETED")
	public boolean isDeleted() {
		return mDeleted;
	}
	
	/**
	 * @param deleted the deleted to set
	 */
	public void setDeleted(boolean deleted) {
		mDeleted = deleted;
	}
	
	/**
	 * @return the deleteInfo
	 */
	@Column(name="DELETE_INFO")
	public String getDeleteInfo() {
		return mDeleteInfo;
	}
	
	/**
	 * @param deleteInfo the deleteInfo to set
	 */
	public void setDeleteInfo(String deleteInfo) {
		mDeleteInfo = deleteInfo;
	}
}
